from Res_sensor import image_rec
from Res_sensor import train_resnet
from Res_sensor import tf_resnet
import torch
import numpy as np
from torch import nn 
from torch.autograd import Variable
import torch.nn.functional as F
from torch.utils.data import DataLoader
from datetime import datetime

import os

if not os.path.exists("data\\data_total.txt"):
    path = "data\\32_32Gesture"
    files = os.listdir(path)
    data = np.zeros((1,1025))
    for file in files:
        position = path + "\\" + file
        print(position)
        da = np.loadtxt(position)
        data = np.append(data, da, axis=0)
    np.savetxt("data\\data_total.txt", data, fmt= '%.3f')

data = np.loadtxt("data\\data_total.txt")

data_train = DataLoader(data[0:7000,:], 128, shuffle=True)
data_test = DataLoader(data[7000:-1,:], 128, shuffle=False)

gesture_net = image_rec(1)
optim = torch.optim.SGD(gesture_net.parameters(), lr=0.001)
cre = nn.CrossEntropyLoss()
train_resnet(gesture_net, data_train, data_test, 10, optim, cre)
